<!--
 * @Description: 转发
-->
<template>
  <ul id="summary-forward">
    <li>
      <span>{{ $i18n('common.select.person.label') }}</span
      ><SelectPeople :options="options" :selected.sync="selected" />
    </li>
    <li>
      <span>{{ $i18n('common.postscript.label') }}</span>
      <div><a-textarea v-model="currentComment" allowClear :maxLength="2000" :rows="4" /></div>
    </li>
    <li class="options">
      <div>
        <a-checkbox v-model="forwardPostscript">{{
          $i18n('collaboration.forward.page.label2')
        }}</a-checkbox>
        <a-checkbox v-model="forwardComment">{{
          $i18n('collaboration.forward.page.label3')
        }}</a-checkbox>
        <a-checkbox v-model="trace">{{ $i18n('permission.operation.Track') }}</a-checkbox>
        <UploadAtt
          :fileList="currentAtt"
          :isSetSecretLevel="isSetSecretLevel"
          :request="{
            upload: api.uploadFileUpload,
            getState: api.uploadGetFileState
          }"
          :maxSize="businessData.other.fileUploadMaxSize" />
        <RelationDoc @selected="(dataList) => (currentDoc = dataList)" :area="docArea" />
      </div>
    </li>
    <li>
      <div>
        <AccessoryItem
          v-if="currentAtt.length"
          :dataList="currentAtt"
          hasDelete
          @deleteItem="(index) => currentAtt.splice(index, 1)" />
        <AccessoryItem
          v-if="currentDoc.length"
          :dataList="currentDoc"
          @deleteItem="(index) => currentDoc.splice(index, 1)"
          isDoc
          :areaName="docArea"
          hasDelete />
      </div>
    </li>
  </ul>
</template>
<script>
  import { useSummaryCommentStore } from '@/store/modules/summary/comment.js';
  // 引入基础数据
  import { useBaseInfoStore } from '@/store/modules/base-info.js';
  import { mapState } from 'pinia';

  import SelectPeople from '@/components/atom/select-people';
  // 上传附件
  import UploadAtt from '@/components/upload-att';
  // 关联文档
  import RelationDoc from '@/components/relation-doc';
  //引入附件、文档列表组件
  import AccessoryItem from '@/components/atom/accessory-item';
  //引入关联文档对象操作
  import { clearArea } from '@/helper/relation-doc';
  import api from '@/api';

  export default {
    name: 'SummaryForward',
    components: { SelectPeople, UploadAtt, RelationDoc, AccessoryItem },
    props: {
      isSetSecretLevel: {
        type: Boolean
      },
      //密级程度
      secretLevel: {
        type: String
      }
    },
    data() {
      return {
        //选人配置
        options: {
          panels:
            'OcipOrganization,Department,BusinessDepartment,Team,Post,Outworker,RelatePeople,JoinOrganization,OrgMetadataTag',
          selectType:
            'Account,Department,Team,Post,Outworker,RelatePeople,Member,BusinessDepartment,BusinessAccount,OrgMetadataTag',
          maxSize: 100,
          hiddenColAssignRadio: true,
          hiddenMultipleRadio: true,
          isConfirmExcludeSubDepartment: true,
          accessFileSecretLevel: this.secretLevel,
          defaultDataAccountId: '',
          excludeElementsBeyondMemberSize: 'Department|3000,Post|3000,Team|3000,Level|3000',
          type: 'selectPeople',
          unallowedSelectEmptyGroup: true,
          showFlowTypeRadio: true,
          mode: '',
          memberWithDeptInfo: true
        },
        //关联文档区域
        docArea: 'forwardPostscript',
        //选人
        selected: {
          text: '',
          value: ''
        },
        //附言
        currentComment: '',
        //附件
        currentAtt: [],
        //关联文档
        currentDoc: [],
        //转发原附言
        forwardPostscript: true,
        //转发原意见
        forwardComment: true,
        //跟踪
        trace: true
      };
    },
    computed: {
      ...mapState(useSummaryCommentStore, ['commentText', 'attachments', 'relationDoc']),
      ...mapState(useBaseInfoStore, ['businessData'])
    },
    created() {
      //把上下文传递给父级
      this.$emit('getContext', this);
      //清除关联文档
      clearArea(this.docArea);
      //初始化
      this.currentComment = this.commentText;
      this.currentAtt = this.attachments.slice();
      this.currentDoc = this.relationDoc.slice();
      this.api = api;
    },
    methods: {
      //返回调接口用的数据
      getData() {
        return {
          comment: this.currentComment,
          att: this.currentAtt,
          doc: this.currentDoc,
          selected: this.selected
        };
      }
    }
  };
</script>
<style lang="scss">
  .summary-forward {
    .ant-modal-confirm-body > .anticon + .ant-modal-confirm-title + .ant-modal-confirm-content {
      margin-left: 0;
    }
  }
</style>
<style lang="scss" scoped>
  #summary-forward {
    padding: 20px;

    > li {
      display: flex;
      margin-bottom: 20px;

      > span {
        width: 65px;
        padding-top: 4px;
        text-align: right;
      }

      > div {
        margin-left: 20px;
        flex: 1;
      }

      &.options {
        margin-left: 85px;

        > div {
          display: flex;
          flex-wrap: wrap;

          > div {
            margin-top: 5px;
            margin-right: 5px;
          }
        }
      }
    }
  }
</style>
